<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';
//print_r($_SESSION);
$smarty->compile_check = true;

if($_GET[action]=='del'){
    foreach($_POST[del] as $key => $value ){
	    $delarr[] = " re_aliasid  = '".$value."' "; 
	}
	$appid = @implode( " OR " ,$delarr);
	$sql = "DELETE FROM pa_contact WHERE $appid ";
}

$smarty->display('header.tpl');
if($_GET[country]==''){
$_GET[country] = 211;
}
//getvalues
$smarty->assign('s',$_GET);
//jobupdate
$smarty->assign('jobupdate_names',$UPDATE);
$smarty->assign('state',$state);
$smarty->assign('country',$country);
$smarty->assign('industry',$jobcategory);
$smarty->assign('status',$jobfillstatus);
$smarty->assign('submitstatus',$submitstatus);
$smarty->assign('jobtype',$jobtype);
$smarty->assign('salary',$salary);


//print_r($findjob_orderby3);

$where = "  WHERE a.jo_id = b.re_aliasid AND b.re_uid = '".$_SESSION[uid]."' ";
$order = " GROUP BY a.jo_id  ORDER BY b.re_regtime DESC";
if($_GET[action]=="search"){ 
	if($_GET[copname]!=''){ $arr[]  = " `jo_copname`  like '%".$_GET[copname]."%'  ";}
	if($_GET[title]!=''){ $arr[]    = " `jo_title` like '%".$_GET[title]."%'  "; }
	if($_GET[status]!='0'&&$_GET[status]!='') { $arr[] = " `jo_status` = '".$_GET[status]."'  ";}
	$a = strtotime($_GET[submitdate]) + 86400 ;
	if($_GET[submitdate]!=''){ $arr[]  = " (`jo_regtime` > '".strtotime($_GET[submitdate])."' AND `jo_regtime` < '".$a."') ";}
	if($_GET[salary]!='0'&&$_GET[salary]!='')    { $arr[]  = " `jo_salrange` = '".$_GET[salary]."'  ";}
	if($_GET[jobreq]!='')    { $arr[]  = " `jo_id`  like  '%".$_GET[jobreq]."%'  ";}
	if($_GET[submitstatus] == 3 ) { $arr[] = " `jo_status` = '3' "; }
	if($_GET[submitstatus] == 2 ) { $arr[] = " (`jo_status` <> '3' AND re_isapproved <> 0) "; }
	if($_GET[submitstatus] == 1 ) { $arr[] = " (`jo_status` <> '3' AND re_isapproved = 0) "; }

	if(!empty($arr)){
		$implode  = @implode("AND", $arr);
		$implode  = " AND ".$implode;
		$where    .= $implode;
	}
}


if($_GET[tp]==3){
	$by    = "b.re_regtime"; 
	$order = "DESC" ;
	
	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "a.jo_id";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "b.re_regtime";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "a.jo_title";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "a.jo_copname";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "a.jo_status";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "b.re_isapproved";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 7:
		   $by = "count";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr3",$order_arr);
		$smarty->assign("image_arr3",$image_arr);

		$order = " GROUP BY a.jo_id  ORDER BY $by $order";
}

//echo "SELECT * FROM pa_job $where $order";
$nav = new buildNav;
$nav->offset = "offset3";
$nav->limit= 25;
$result = $DB->query("SELECT COUNT(*) AS count FROM pa_job as a ,pa_contact as b $where $order");

$count3 = 0;
while($list = $DB->fetch_array($result)){
  $count3++;
}
//echo $count2;
//echo "SELECT COUNT(*) AS count, b.*,a.jo_copname,a.jo_id,a.jo_title,a.jo_salrange,a.jo_status,c.re_fname,c.re_lname FROM pa_job as a ,pa_applicant as b , pa_resume as c $where $order";
$nav->total_result = $count3;
$nav->execute("SELECT COUNT(*) AS count, b.*,SUM(b.re_isapproved) as re_isapproved, a.jo_copname,a.jo_id,a.jo_title,a.jo_salrange,a.jo_status, a.jo_regtime FROM pa_job as a ,pa_contact as b $where $order");

$i=0;

while($list3 = $DB->fetch_array($nav->sql_result)){
   $datajob3[$i]                = $list3;
   $datajob3[$i][id]            = $list3[re_aliasid];
   if($list3[re_regtime]!=''){
	   $datajob3[$i][re_regtime] = date("m/d/Y",$list3[re_regtime]);
   }
   $datajob3[$i][title]         = $list3[jo_title];
   
   $datajob3[$i][status] = 1;
   if($list3[jo_status] <> 3 && $list3[re_isapproved] > 0){$datajob3[$i][status] = 2;}
   if($list3[jo_status] == 3){$datajob3[$i][status] = 3;}


   $datajob3[$i][jo_applicants] = getNumberOfContacted($datajob3[$i][jo_id],1);
   $datajob3[$i][jo_salrange]   = $salary[$list3[jo_salrange]];

   $sql = "SELECT count(*) as count FROM pa_applicant WHERE app_jobid='".$list3['jo_id']."' AND app_recruitid ='".$_SESSION['uid']."' AND app_owntype='recruiter' ";
   $appInfo = $DB->fetch_one_array($sql);
   $datajob3[$i]['appcount'] = ($appInfo['count']>0)?'<a href="applicantlist.php?id='.$list3['jo_id'].'">'.$appInfo['count'].'</a>':0;
   $i++;
}

$smarty->assign("joblist3",$datajob3);
$page3 = $nav->pagenav();
$smarty->assign("page3",$page3);

if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("search",$reg_data);
$smarty->display('allleft.tpl');
$smarty->display('mycontactjobs.tpl');
$smarty->display('footer.tpl');
?>